// const apiURL = 'https://124.221.119.116:8080';
const apiURL = 'https://www.doudouxny.com';

const wxRequest2 = (params, url) => {
        wx.request({
            url,
            method: params.method || 'GET',
            data: params.data || {},
            header: {
              Accept: 'application/json',
              'Content-Type': 'application/json',
              authorization: wx.getStorageSync('token')
            },
            success(res) {
                if(res.statusCode==401){
                    wx.showToast({
                      title: '登录失效，请重新登录',
                    })
                    wx.navigateTo({
                      url: '/pages/login2/index',
                    })
                }
              if (params.success) {
                params.success(res);
              }
            },
            fail(res) {
                console.log('111',res)
              if (params.fail) {
                params.fail(res);
              }
            },
            complete(res) {
              if (params.complete) {
                params.complete(res);
                console.log('111',res)
              }
            },
          });
    
  
};

const wxRequest = (params, url) => {
  wx.request({
    url,
    method: params.method || 'GET',
    data: params.data || {},
    header: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
    success(res) {
      if (params.success) {
        params.success(res);
      }
    },
    fail(res) {
      if (params.fail) {
        params.fail(res);
      }
    },
    complete(res) {
      if (params.complete) {
        params.complete(res);
      }
    },
  });
};

const getHotTripList = (params) => {
  wxRequest(params, `${apiURL}/v2/index/`);
};

const getCategoryList = (params) => {
    wxRequest(params, `${apiURL}/doudou/categorylist`);
};
const getCarList = (params) => {
    wxRequest(params, `${apiURL}/doudou/productlist`);
};

const productlist = (params) => {
    wxRequest(params, `${apiURL}/doudou/productlist`);
};

const sendCode = (params) => {
    wxRequest(params, `${apiURL}/doudou/sendcaptcha`)
}

const login = (params) => {
  wxRequest(params, `${apiURL}/doudou/clientlogin`)
}

const productinfo = (params) => {
    wxRequest(params, `${apiURL}/doudou/productinfo/${params.id}`)
  }

  const collectionlist = (params) => {
    wxRequest(params, `${apiURL}/doudou/collectionlist`)
  }

const categorysearch = (params) => {
wxRequest(params, `${apiURL}/doudou/categorysearch`)
}

const qualitylist = (params) => {
wxRequest(params, `${apiURL}/doudou/qualitylist`)
}

const recommendlist = (params) => {
  wxRequest(params, `${apiURL}/doudou/recommendlist`)
  }
const orderlist = (params) => {
wxRequest(params, `${apiURL}/doudou/orderlist`)
}  
const orderadd = (params) => {
  wxRequest(params, `${apiURL}/doudou/orderadd`)
  }

  const collectionadd = (params) => {
    wxRequest(params, `${apiURL}/doudou/collectionadd`)
    }
const carousellist = (params) => {
wxRequest(params, `${apiURL}/doudou/carousellist`)
}
const collectionexist = (params) => {
wxRequest(params, `${apiURL}/doudou/collectionexist`)
}
const collectiondel = (params) => {
    wxRequest(params, `${apiURL}/doudou/collectiondel`)
    }
const productnewrecommend = (params) => {
    wxRequest(params, `${apiURL}/doudou/productnewrecommend`)
    }


const login2 = (params) => {
    wxRequest(params, `${apiURL}/doudou/login`)
}
const businesslist = (params) => {
    wxRequest2(params, `${apiURL}/doudou/businesslist`)
}
const productadd = (params) => {
    wxRequest2(params, `${apiURL}/doudou/productadd`)
}
const productupdate = (params) => {
  wxRequest2(params, `${apiURL}/doudou/productupdate`)
}

const productdel = (params) => {
  wxRequest2(params, `${apiURL}/doudou/productdel`)
}

const businessadd = (params) => {
  wxRequest2(params, `${apiURL}/doudou/businessadd`)
}

const orderadminlist = (params) => {
    wxRequest2(params, `${apiURL}/doudou/orderadminlist`)
}
const businesschangestatus = (params) => {
  wxRequest2(params, `${apiURL}/doudou/businesschangestatus`)
}

const marketlist = (params) => {
    wxRequest2(params, `${apiURL}/doudou/marketlist`)
  }

  const marketuserlist = (params) => {
    wxRequest2(params, `${apiURL}/doudou/marketuserlist`)
  }
  
  const userinfo = (params) => {
    wxRequest(params, `${apiURL}/doudou/userinfo`)
    }

    const userchange = (params) => {
      wxRequest2(params, `${apiURL}/doudou/userchange`)
      }

      const getopendid = (params) => {
        wxRequest(params, `${apiURL}/doudou/getopendid`)
        }
      

module.exports = {
  userinfo,
  getopendid,
  userchange,
  businesschangestatus,
  businessadd,
  marketuserlist,
  marketlist,
  getHotTripList,
  orderadminlist,
  businesslist,
  getCategoryList,
  getCarList,
  productlist,
  productupdate,
  productdel,
  productadd,
  sendCode,
  login,
  login2,
  productinfo,
  collectionlist,
  categorysearch,
  qualitylist,
  recommendlist,
  orderlist,
  orderadd,
  collectionadd,
  carousellist,
  collectionexist,
  collectiondel,
  productnewrecommend
};